package com.example.designmode.responsibility


/**
 * 抽象处理者
 * 定义一个处理请求的接口，包含抽象处理方法和一个后继连接
 *
 * @author zhouronghua
 * @time 2022/3/9 3:18 下午
 */
abstract class Handler(var numStart: Int, var numEnd: Int) {

    companion object {
        const val oneDay = 1

        const val threeDay = 3

        const val sevenDay = 7
    }

    /**
     * 上级领导对象
     */
    var nextHandler: Handler? = null

    /**
     * 处理请假请求
     *
     * @author zhouronghua
     * @time 2022/3/9 3:28 下午
     */
    abstract fun handleRequest(request: LeaveRequest)

    /**
     * 提交请假条
     *
     * @author zhouronghua
     * @time 2022/3/9 3:29 下午
     */
    fun submit(request: LeaveRequest) {
        this.handleRequest(request)
        if (nextHandler != null && request.days > numEnd) {
            nextHandler?.submit(request)
        } else {
            println("===请假流程结束===")
        }
    }
}